package logic

import (
	"context"
	"errors"
	"gorm.io/gorm"
	"user-srv/model/mysql"

	"user-srv/internal/svc"
	"user-srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserIdInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserIdInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserIdInfoLogic {
	return &GetUserIdInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetUserIdInfoLogic) GetUserIdInfo(in *user.GetUserIdInfoRequest) (*user.GetUserIdInfoResponse, error) {
	// todo: add your logic here and delete this line
	r := mysql.RealAuth{
		UserId: in.UserId,
	}
	err := r.GetUserIdInfo()
	if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
		return nil, errors.New("获取实名信息失败")
	}
	return &user.GetUserIdInfoResponse{
		UserId:   r.UserId,
		ID:       int64(r.ID),
		RealName: r.RealName,
		IdCard:   r.IdCard,
	}, nil
}
